package com.yqg.education.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yqg.education.common.Result;
import com.yqg.education.entity.BlackKeyword;
import com.yqg.education.service.IBlackKeywordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * BlackKeywordController 前端控制器
 * @author 张芸博
 * @since 2025-04-10
 */
@RestController
@RequestMapping("/black-keyword")
public class BlackKeywordController {

    @Resource
    private IBlackKeywordService blackKeywordService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody BlackKeyword blackKeyword) {
        return Result.success(blackKeywordService.saveOrUpdate(blackKeyword));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        BlackKeyword blackKeyword =blackKeywordService.getById(id);
        return Result.success(blackKeywordService.saveOrUpdate(blackKeyword));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<BlackKeyword> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<BlackKeyword> list=  blackKeywordService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(blackKeywordService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<BlackKeyword> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        queryWrapper.orderByDesc("id");
        return Result.success(blackKeywordService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

